//https://dart.cn/language/#interfaces-and-abstract-classes
/**
所有的类都隐式定义成了一个接口。因此，任意类都可以作为接口被实现。
 */

import 'my_mixins.dart';
import 'my_classes.dart';

// 抽象类 Describable
abstract class Describable {
  void describe();
  
  void describeWithEmphasis() {
    print('=========');
    describe();
    print('=========');
  }
}


class MockSpaceship implements Spacecraft {
  // 移除 final，允许修改
  @override
  String name;
  
  @override
  DateTime? launchDate;
  
  @override
  int? get launchYear => launchDate?.year;
  
  @override
  void describe() {
    print('MockSpaceship: $name');
    var launchDate = this.launchDate;
    if (launchDate != null) {
      int years = DateTime.now().difference(launchDate).inDays ~/ 365;
      print('Launched: $launchYear ($years years ago)');
    } else {
      print('Unlaunched');
    }
  }
  
  MockSpaceship(this.name, this.launchDate);
  
  MockSpaceship.unlaunched(String name) : this(name, null);
}
void main() {
  // 使用 MockSpaceship
  var mock = MockSpaceship('Test Ship', DateTime.now());
  mock.describe();
}

